<?php

/**
 * This is the model class for table "golf_land".
 *
 * The followings are the available columns in table 'golf_land':
 * @property integer $id_golf
 * @property integer $id_kab
 * @property string $name
 * @property string $base_price
 * @property string $base_time_start
 * @property string $base_time_end
 * @property integer $base_tee
 *
 * The followings are the available model relations:
 * @property Kabupaten $idKab
 * @property SystemRate[] $systemRates
 * @property TeeTimeOnline[] $teeTimeOnlines
 */
class GolfLand extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return GolfLand the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'golf_land';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_kab', 'required'),
			array('id_golf, id_kab, base_tee', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>32),
			array('base_price', 'length', 'max'=>8),
			array('base_time_start, base_time_end', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_golf, id_kab, name, base_price, base_time_start, base_time_end, base_tee', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idKab' => array(self::BELONGS_TO, 'Kabupaten', 'id_kab'),
			'systemRates' => array(self::HAS_MANY, 'SystemRate', 'id_golf'),
			'teeTimeOnlines' => array(self::HAS_MANY, 'TeeTimeOnline', 'id_golf'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_golf' => 'Id Golf',
			'id_kab' => 'Id Kab',
			'name' => 'Name',
			'base_price' => 'Base Price',
			'base_time_start' => 'Base Time Start',
			'base_time_end' => 'Base Time End',
			'base_tee' => 'Base Tee',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_golf',$this->id_golf);
		$criteria->compare('id_kab',$this->id_kab);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('base_price',$this->base_price,true);
		$criteria->compare('base_time_start',$this->base_time_start,true);
		$criteria->compare('base_time_end',$this->base_time_end,true);
		$criteria->compare('base_tee',$this->base_tee);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}